package com.google.code.avajhelpdesk.entities;

import java.util.HashMap;
import java.util.Map;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinTable;
import javax.persistence.JoinColumn;

import org.hibernate.annotations.CollectionOfElements;
import org.hibernate.annotations.MapKey;

public class Contract {
	
    private Long id;

    private String name;

    private Map<String, String> atributes = new HashMap<String, String>();
    
    @Id @GeneratedValue(strategy=GenerationType.AUTO)
    public Long getId() { return id; }

    @SuppressWarnings("unused")
    private void setId(Long id) { this.id = id; }


	@Column(length = 255, nullable = false)
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Just for hibernate
	 */
	@SuppressWarnings("unused")
	private void setAtributes(Map<String, String> atributes) {
		this.atributes = atributes;
	}

	@CollectionOfElements
	@JoinTable(name="contract_attributes", joinColumns = @JoinColumn(name="contract_id"))
	@MapKey(columns={@Column(name="attr_name",length=255)})
	@Column(name="attr_value")
	private Map<String, String> getAtributes() {
		return atributes;
	}
	
	public void setAttribute(String key, String value) {
		this.atributes.put(key, value);
	}
	
	public String getProperty(String key) {
		return this.atributes.get(key);
	}
		
}
